//
// Created by xili on 2024/8/2 21:45.
// Go big or go home.
//

using namespace std;

class Solution {
public:
    int pivotInteger(int n) {
        int total = (n + 1) * n / 2;
        int sum = 0;
        for (int i = 1; i < n; i++) {
            sum += i;
            if (2 * sum - i == total) {
                return i;
            }
        }
        return -1;
    }
};